﻿using Logistics.Apply;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace Logistics.Web.Controllers
{
    /// <summary>
    /// 发票
    /// </summary>
    public class InvoiceController : Controller
    {
        private readonly InvoiceAppService _invoiceAppService;
        public InvoiceController(InvoiceAppService invoiceAppService)
        {
            _invoiceAppService = invoiceAppService;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task DeleteAsyncc(int id)
        {
            var i = _invoiceAppService.DeleteAsync(id);
            return i;
        }
        /// <summary>
        /// 查看视图
        /// </summary>
        /// <returns></returns>
        public ActionResult GetInvoiceIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        /// <summary>
        /// 反填视图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult PutInvoiceIndex(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        public IActionResult Updates(InvoiceDto invoice)
        {
            var procur = _invoiceAppService.UpdateAsync(invoice);
            return Ok(procur);
        }

        /// <summary>
        /// 查看详情/反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task<InvoiceDto> GetAsyncc(int id)
        {
            var Procur = _invoiceAppService.GetAsync(id);
            return Procur;
        }
        /// <summary>
        /// 添加视图
        /// </summary>
        /// <returns></returns>
        public ActionResult PostInvoiceIndex()
        {
            return View();
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="Procurement"></param>
        /// <returns></returns>
        public IActionResult Add(InvoiceDto invoice)
        {
            var i = _invoiceAppService.CreateAsync(invoice).Result;
            return Ok(i);
        }
        /// <summary>
        /// 主页显示
        /// </summary>
        /// <returns></returns>
        public ActionResult GatheringIndex()
        {
            return View();
        }
        // GET: ApproveController/Details/5
        public JsonResult ShowInvoice(GetInvoiceListDto getInvoiceListDto)
        {
            var getInvoiceList = _invoiceAppService.GetListAsync(getInvoiceListDto).Result;
            return Json(new { data = getInvoiceList.Items, count = getInvoiceList.TotalCount, code = "0", msg = "" });
        }
    }
}
